<!DOCTYPE html>
<html lang="zh">
<head>
    <th:block th:include="include :: header('文件上传')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <input type="hidden" id="schoolId" th:value="${schoolId}">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="form-group">
                        <label class="font-noraml">文件上传</label>
                        <div class="file-loading">
                            <input id="multipleFile" name="files" type="file" multiple>
                        </div>
                    </div>
                    <hr>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var schoolId = $("#schoolId").val();
    $(document).ready(function () {
        // 多图上传
        $("#multipleFile").fileinput({
            uploadUrl: ctx + 'common/uploads',
            uploadAsync: false
        }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
            var rsp = data.response;
            var table_name_alias = "学校文件夹";
            var table_name = "teaching_school";
            var table_key = schoolId;
            if (rsp.code == 0) {
                var teachingFile = [];
                let urls = rsp.urls.split(",");
                let fileNames = rsp.fileNames.split(",");
                let newFileNames = rsp.newFileNames.split(",");
                let originalFilenames = rsp.originalFilenames.split(",");
                $.each(urls, function (index, value) {
                    let file = {};
                    file.tableNameAlias = table_name_alias;
                    file.tableName = table_name;
                    file.tableKey = table_key;
                    file.fileNameOriginal = originalFilenames[index];
                    file.filePath = fileNames[index];
                    file.fileName = newFileNames[index];
                    teachingFile.push(file);
                });
                // $.operate.saveTab(ctx + "teaching/school/uploadFile",JSON.stringify(teachingFile))
                $.ajax({
                    url: ctx + "teaching/school/uploadFile",
                    method: "post",
                    contentType: "application/json",
                    dataType: "json",
                    data: JSON.stringify(teachingFile),
                    success: function (result) {
                        $.operate.successTabCallback(result);
                    }
                })
            }
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
    });
</script>
</body>
</html>
